/*
 * @Author: zhangsai
 * @Date: 2018/1/16
 * @Last Modified by: zhangsai
 * @Last Modified time: 2018/1/16
 * @description: 文件列表 混合
 */

import { api } from './api';
import { STATUS_HTTP_SUCCESS, apiHttp } from '__service/csHttp';
import mined from '__components/file-list/fileMixin.js';
export default {
    mixins: [mined],
    data() {
        return {
            // 参数
            params: {
                reportName: '',
                reportType: this.$route.params.id,
                pageIndex: 1,
                pageSize: this.vuePageSize,
            },
            fileList: {

            },
            fileChildTypeList: [],
            fullLoading: false
        }
    },
    methods: {
        getDefaultInfo() {
            this.getReportList();
        },
        // 获取报告列表
        async getReportList() {
            this.params.reportType = this.$route.params.id;
            let params = this.params;
            let resData = await apiHttp(api.GET_REPORT_LIST, params);
            if (resData.resCode === STATUS_HTTP_SUCCESS) {
                this.fileList = resData.data || {};
            }
        },
        // 分页
        handleCurrentChange(val) {
            this.params = {...this.params, pageIndex: val};
            this.getReportList();
        },
        // 删除文件
        deleteFile(id,index) {
            let params = {
                id: id
            };
            this.$confirm('确认删除此文件?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let resData = await apiHttp(api.DELETE_FILE, params);
                if (resData.resCode === STATUS_HTTP_SUCCESS) {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    if (arguments.length === 1) {
                        this.getReportList();
                        if (this.deleteFileId ) {
                            this.deleteFileId(id)
                        }
                    } else {
                        this.fileShowListArr.splice(index,1) //删除文件 页面显示删除
                        if (this.deleteFileId) {
                            this.deleteFileId(id)
                        }
                        //console.log(this.fileShowListArr,"删除后的文件列表")
                    }
                }
            })
        },
    }
}
